﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Kenly.DBFramework.Gateway
{
    /// <summary>
    /// StoredProcedure object to execute a stored pocedure hosted in database.
    /// </summary>
    public interface IStoredProcedure
    {
        //object Execute();

        /// <summary>
        /// Begins a database transaction with 60s active time.
        /// </summary>
        /// <returns></returns>
        bool BeginTransaction();

        /// <summary>
        /// Commits the database transaction.
        /// </summary>
        /// <returns></returns>
        bool Commit();

        /// <summary>
        /// Rolls the database transaction.
        /// </summary>
        /// <returns></returns>
        bool Rollback();



        /// <summary>
        /// Executes a procedure or sql statement ,and returns the number of rows affected.
        /// </summary>
        /// <returns></returns>
        int ExecuteNonQuery();

        /// <summary>
        /// Executes a procedure or sql statement ,and returns the first column of the first row of the resultset.
        /// </summary>
        /// <returns></returns>
        object ExecuteScalar();

        /// <summary>
        /// Executes a procedure or sql statement ,and builds an IDataReader.
        /// </summary>
        /// <returns></returns>
        IDataReader ExecuteReader();

        /// <summary>
        /// Close the DataReader and the connection to database.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        void CloseReader(IDataReader reader);

        /// <summary>
        /// Executes a procedure or sql statement ,and returns a DataTable.
        /// </summary>
        /// <returns></returns>
        DataTable ExecuteDataTable();

        /// <summary>
        /// Executes a procedure or sql statement ,and returns a DataTable.
        /// </summary>
        /// <returns></returns>
        DataTable ExecuteDataTable<TTarget>() where TTarget : new();

        /// <summary>
        /// Executes a procedure or sql statement ,and returns an array of entities.
        /// </summary>
        /// <returns></returns>
        List<TTarget> ExecuteEntity<TTarget>() where TTarget : new();

        /// <summary>
        /// Executes a procedure or sql statement ,and returns a DataSet.
        /// </summary>
        /// <returns></returns>
        DataSet ExecuteDataSet();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        void RefreshConfig(GatewayConfig config);
    }
}
